package com.kingdee.eas.hr.quali.util;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.compensation.util.SqlUtil;

public class QualificationUtils {

	public static Map<String, Object> getDataMap(Context ctx, String personId) {
		Map<String, Object> dataMap = new HashMap<String,Object>();
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT stand.fname as quatype,level.fname_l2 as quaLevel,qua.cfbeginDate as quaStartDate, \n");
		sql.append("pp.FJOINGROUPDATECUR as joinDateCur,oneORg.fname_l2 as oneOrgName, \n");
		sql.append("pos.fname_l2 as positionName,person.fname_l2 as personName,person.Fnumber as personNumber, \n");
		sql.append("adminOrg.fname_l2 as adminOrgName,empType.Fname_l2 as empName  FROM T_HR_PErsonPosition pp \n");
		sql.append("LEFT OUTER JOIN T_BD_Person person ON pp.FPERSONID = person.FID  \n");
		sql.append("LEFT OUTER JOIN T_HR_BDEmployeeType empType ON person.FEmployeeTypeID = empType.FID \n");
		sql.append("LEFT OUTER JOIN T_Org_position pos ON PP.FPRIMARYPOSITIONID = POS.FID  \n");
		sql.append("LEFT OUTER JOIN T_ORG_admin adminOrg ON PP.FPERSONDEP = ADMINORG.FID \n");
		sql.append("LEFT OUTER JOIN T_ORG_Admin oneORg ON adminOrg.FLEVELTWOGROUPID = ONEORG.FID \n");
		sql.append("LEFT OUTER JOIN CT_MP_PersonPosQualification qua ON pp.FPERSONID = qua.fpersonid \n");
		sql.append("LEFT OUTER JOIN CT_QUA_QualificationsStandard stand ON qua.cfstandardsid = stand.fid \n");
		sql.append("LEFT OUTER JOIN CT_QUA_QualificationsLevel level ON qua.cfqualilevelid = level.fid \n");
		sql.append("where person.FID = '"+personId+"' order by qua.CFEndDate desc \n");
		try {
			IRowSet iRowSet = SqlUtil.executeQuery(ctx, sql.toString());
			if(iRowSet.next()){
				dataMap.put("quaType", iRowSet.getString("quatype") == null ? "" : iRowSet.getString("quatype"));
				dataMap.put("quaLevel", iRowSet.getString("quaLevel")  == null ? "" : iRowSet.getString("quaLevel"));
				dataMap.put("quaStartDate", iRowSet.getString("quaStartDate") == null ? "" : iRowSet.getString("quaStartDate").substring(0, 10));
				dataMap.put("positionName", iRowSet.getString("positionName"));
				dataMap.put("adminOrgName", iRowSet.getString("adminOrgName"));
				dataMap.put("oneOrgName", iRowSet.getString("oneOrgName"));
				dataMap.put("joinDateCur", iRowSet.getString("joinDateCur") == null ? "" : iRowSet.getString("joinDateCur").substring(0, 10));
				dataMap.put("empName", iRowSet.getString("empName"));
				dataMap.put("name", iRowSet.getString("personName"));
				dataMap.put("number", iRowSet.getString("personNumber"));
			}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dataMap;
	}
	
}
